package com.cxb.java.strategy;

/**
 * @Classname StrategyDemo
 * @Date 2023/8/18 22:35
 * @Created by Administrator
 * @Description TODO
 */
public class StrategyDemo {
    public static void main(String[] args) {
        // 创建具体策略对象
        Strategy strategyA = new ConcreteStrategyA();
        Strategy strategyB = new ConcreteStrategyB();
        Strategy strategyC = new ConcreteStrategyC();

        // 创建上下文对象，并设置具体策略
        Context context = new Context(strategyA);
        // 执行策略
        context.executeStrategy();

        // 修改策略为 B，并执行
        context = new Context(strategyB);
        context.executeStrategy();

        // 修改策略为 C，并执行
        context = new Context(strategyC);
        context.executeStrategy();
    }
}
